<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var arr = [28, 5, 11, 9, 2, 35, 18];
    // 定义交换数字时临时存放用变量
    var box;
    // 循环检查所有数字是否已排列完毕
    for (var i = 0; i < arr.length; i++) {
        // 核心语句：判断相邻数字大小并按照大小重新排序
        for (var j = 0; j < arr.length - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                box = arr[j + 1];
                arr[j + 1] = arr[j];
                arr[j] = box;
            }
        }
    }
    document.write(arr);
</script>
</body>
</html>